package com.cloudptt.wp.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.cloudptt.api.product.log.Log;

public class BaseBroadcast extends BroadcastReceiver
{
	public final static String THIS_FILE = "BaseBroadcast";
	private final static String ACTION_HANGUP_DOWN = "FLYPTT.privkey.power.down";
	private final static String ACTION_HANGUP_UP = "FLYPTT.privkey.power.up";

//	private final static String ACTION_PTT_DOWN = "FLYPTT.privkey.power.down";
//	private final static String ACTION_PTT_UP = "FLYPTT.privkey.power.up";
	private Context ctx = null;
	private EventListener listener = null;


	public BaseBroadcast(Context ctx,EventListener listener)
	{
		this.ctx = ctx;
		this.listener = listener;
		IntentFilter filter = new IntentFilter();
		filter.addAction(ACTION_HANGUP_DOWN);/**蓝牙指环PTT**/
		filter.addAction(ACTION_HANGUP_UP);
		if(filter != null){
			ctx.registerReceiver(this, filter);
		}
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		String action = intent.getAction();
		Log.e(THIS_FILE, "onReceive: action = " + action);
		if(ACTION_HANGUP_UP.equals(action))
		{
			if (listener != null)
			{
				listener.onHangup(1);
			}
		}
	}

	public void clearResource()
	{
		this.ctx.unregisterReceiver(this);
		this.ctx = null;
		this.listener = null;
	}
}
